package com.gh.receiver;

import com.alibaba.fastjson.JSONObject;
import com.gh.constant.MQConst;
import com.gh.dto.SmsDto;
import com.gh.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Eric Fang
 * @version 1.0
 * @date 2021/11/7 0:20
 */
@Component
@Slf4j
public class SmsReceiver {
    @Resource
    private SmsService smsService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MQConst.QUEUE_SMS_ITEM, durable = "true"),
            exchange = @Exchange(value = MQConst.EXCHANGE_TOPIC_SMS),
            key = {MQConst.ROUTING_SMS_ITEM}
    ))
    public void send(SmsDto smsDto) {
        log.info("消息监听");
        Map<String, Object> param = new HashMap<>();
        param.put("code", smsDto.getMessage());
        smsService.sendCode(param, smsDto.getMobile());
    }
}
